<template>
    <div>

        <el-dialog title="公告详情" :visible.sync="dialogFormVisible" width="500px" >
            <el-form :model="form">
                <el-form-item label="公告标题" label-width="90px">
                    <el-input v-model="form.title" autocomplete="off" placeholder="公告标题" disabled></el-input>
                </el-form-item>
                <el-form-item label="公告内容" label-width="90px">
                    <el-input
                            type="textarea"
                            :rows="5"
                            placeholder="公告内容"
                            v-model="form.context"
                            disabled>
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
            </div>
        </el-dialog>

        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="title"
                    label="标题"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="context"
                    label="内容"
                    width="650"
                    :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column
                    prop="pullTime"
                    label="公告时间"
                    width="200"
                    :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column
                    label="状态"
                    width="60">
                <template slot-scope="scope">
                    <el-tag size="small" v-if="scope.row.state===1">已读</el-tag>
                    <el-tag size="small" v-if="scope.row.state===0">未读</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small" style="margin-right: 10px">查看详情</el-button>
                    <el-popconfirm title="确定删除该文件吗？" @confirm="handleDelete(scope.row)">
                        <el-button
                                slot="reference"
                                type="text"
                                size="mini">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
export default {
    name: "message",
    data(){
        return {
            dialogFormVisible: false,

            form: {
                title: '',
                context: ''
            },
            tableData: [
                {
                    sysMessageid:"1111111111",
                    title:"公告一",
                    context:"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa啊",
                    pullTime:"2021-09-15 16:01:41",
                    state: 1
                }
            ]
        }
    },
    created() {
        this.getMessageList();
    },
    methods: {
        handleDelete(row){
            let vm = this;
            this.axios({
                url: '/myapi/user/notifyAnnounceUser/delete/'+row.sysMessageid,
                method: 'delete'
            }).then(function (response) {
                if(response.data.success === true){
                    vm.$message({
                        message: '删除成功!',
                        type: 'success'
                    });
                    vm.getMessageList();
                }
                else {
                    vm.$message.error('删除失败');
                }
            });
        },
        handleClick(row){
            let vm = this;
            this.axios({
                url: '/myapi/user/notifyAnnounceUser/changeState/'+row.sysMessageid,
                method: 'put'
            }).then(function (response) {
                if(response.data.success === true){
                    vm.form.title = row.title;
                    vm.form.context = row.context;
                    vm.dialogFormVisible = true;
                    vm.getMessageList();
                }
                else {
                    console.log(response.data);
                    vm.$message.error('获取列表失败');
                }
            });

        },
        getMessageList(){
            let vm = this;
            this.axios({
                url: '/myapi/user/notifyAnnounceUser/insert/'+vm.$store.state.id,
                method: 'put'
            }).then(function (response) {
                if(response.data.success === true){

                }
                else {
                    console.log(response.data);
                    vm.$message.error('获取列表失败');
                }
            });
            this.axios({
                url: '/myapi/user/notifyAnnounceUser/list/'+vm.$store.state.id,
                method: 'get'
            }).then(function (response) {
                if(response.data.success === true){
                    vm.tableData = response.data.content;
                    console.log(vm.tableData);
                }
                else {
                    console.log(response.data);
                    vm.$message.error('获取列表失败');
                }
            });
        }
    }
}
</script>

<style scoped>

</style>
